﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.Sound;
using UnityEngine;
using RimWorld;
using Verse.AI;

namespace Miao.Stand
{
    public class TheWorldAbility : StandAbilityContinue
    {
        public override bool Continue
        {
            get
            {
                return command_StandAction.useContinue;
            }
            set
            {
                command_StandAction.useContinue = value;
            }
        }
        public TheWorldAbility(StandPawn stand) : base(stand)
        {


        }
        Command_StandAction command_StandAction;
        private StarPlatinumStand starPlatinum;
        public override void Init()
        {
            base.Init();
            command_StandAction = new Command_StandAction(this);
            SetDefField(command_StandAction);
            command_StandAction.order = 18;
            starPlatinum = (stand as StarPlatinumStand);
            command_StandAction.action = () =>
            {
                //starPlatinum.TheWorld = !starPlatinum.TheWorld;
                if (!starPlatinum.TheWorld && !Continue)
                {
                    if (stand.jobs.curJob.def == StandJobDefOf.TheWorld) return;
                    //StartCast();
                    Job job = JobMaker.MakeJob(StandJobDefOf.TheWorld, this.stand);
                    stand.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                    //command_StandAction.useContinue = true;
                }
                else
                {
                    Find.TickManager.TogglePaused();
                    //command_StandAction.useContinue = false;
                }
            };


        }


        public override Gizmo DrawGizmo()
        {
            if (!starPlatinum.TheWorld)
            {
                bool disabled = PowerCostEnough(command_StandAction) & CooldownComplete(command_StandAction) & GhostFollow(command_StandAction);
                command_StandAction.disabled = !disabled;
            }
            return command_StandAction;
        }
    }
}
